/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.intec.matsab.dao;

import edu.intec.matsab.persistence.Historial;
import edu.intec.matsab.persistence.PersistenceManager;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

/**
 *
 * @author matilde
 */
public class HistorialDAO extends BasicoDAO{

      public static Historial buscarHistorial(String matricula) {
        EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
        EntityManager manager = emf.createEntityManager();

        Historial historial = new Historial();

        try {
            Query query = manager.createNamedQuery("Historial.findByMatricula");
            query.setParameter("matricula", matricula);
            historial = (Historial)query.getSingleResult();

        } catch (PersistenceException exception) {
            exception.printStackTrace();
        } finally {
            manager.close();
        }

        return historial;
      }


      public static List<Historial> buscarEstudiantesdeSeccion(String idTrimestre, String idAsignatura) {
        EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
        EntityManager manager = emf.createEntityManager();

        List<Historial> listEstudiante = new ArrayList<Historial>();

        try {
            Query query = manager.createNamedQuery("Historial.findEstudentsOfSeccion");
            query.setParameter("idTrimestre", idTrimestre);
            query.setParameter("idAsignatura", idAsignatura);
            listEstudiante = (List<Historial>)query.getSingleResult();

        } catch (PersistenceException exception) {
            exception.printStackTrace();
        } finally {
            manager.close();
        }

        return listEstudiante;
      }
}
